module.exports = function($scope, $state, $stateParams, $modalInstance, item,$resource,$modal){  
    console.log(item);
    // var id = item.id;
    // console.log(id);
    $scope.info = item;
    $scope.ok = function(){
        if(item != undefined){
            var para = {
                'id' : item.id
            }
            para = angular.extend(para,$scope.info);       
            console.log(para);
            $resource('/api/as/mc/merhotsearchdao/updateHotSearch', {}, {}).
            save($scope.info,function(res){
                if(res.errcode != 0){
                    toaster.success({title: "", body:res.errmsg});
                    return;
                }
                console.log(res);
                alert('修改成功');
                // toaster.success({title: "", body:"修改成功"});
                $modalInstance.close();
            })
        } else {
            // toaster.success({title: "", body:"请将数据补充完整"});
            if($scope.info.value!=''&&$scope.info.type!=''){
                console.log($scope.info);
                $resource('/api/as/mc/merhotsearchdao/save', {}, {}).                
                save($scope.info,function(res){
                    if(res.errcode!=0){
                        toaster.success({title: "", body:res.errmsg});
                        return;
                    }
                    console.log(res);
                    alert('添加成功');
                    // toaster.success({title: "", body:"添加成功"});
                    $modalInstance.close();
                })
            } else {
                toaster.success({title: "", body:"请将数据补充完整"});

            }

        }

        
        // if(id){
        //     if($scope.info.value!=''&&$scope.info.type!=''){
        //         updateHotSearch.save($scope.info,function(res){
        //             if(res.errcode != 0){
        //                 toaster.success({title: "", body:res.errmsg});
        //                 return;
        //             }
        //             console.log(res);
        //             toaster.success({title: "", body:"修改成功"});
        //             $uibModalInstance.close();
        //         })
        //     } else {
        //         toaster.success({title: "", body:"请将数据补充完整"});
        //     }
        
        // } else {
        //     if($scope.info.value!=''&&$scope.info.type!=''){
        //         console.log($scope.info);
        //         saveHotSearch.save($scope.info,function(res){
        //             if(res.errcode!=0){
        //                 toaster.success({title: "", body:res.errmsg});
        //                 return;
        //             }
        //             console.log(res);
        //             toaster.success({title: "", body:"添加成功"});
        //             $uibModalInstance.close();
        //         })
        //     } else {
        //         toaster.success({title: "", body:"请将数据补充完整"});

        //     }
        // }
        
}
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };

};